﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Agile.Engine.View;

namespace Fis.Win.Forms
{
    public partial class BaseForm : DevExpress.XtraEditors.XtraForm, IView
    {
        public BaseForm()
        {
            InitializeComponent();
        }

        #region Implement the IView
        public System.Collections.Hashtable ViewModel { get; set; }

        public Agile.Engine.View.IViewProvider ViewProvider { get; set; }

        public virtual void InitializeViewUI()
        {
            
        }

        public virtual void InitializeBinding()
        {
        }

        public Agile.Engine.View.ViewState ViewState { get; set; }

        public virtual string Message { get; set; }

        public string KeyWords { get; set; }
        #endregion

        private void BaseForm_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                if (BeforeEscapeClose())
                {
                    ViewResult = DialogResult.Cancel;
                    this.Close();
                }
            }
        }

        protected virtual void ShowMessage(string msg)
        {
            if (!string.IsNullOrEmpty(msg))
                XtraMessageBox.Show(msg);
        }

        protected virtual bool BeforeEscapeClose()
        {
            var v = XtraMessageBox.Show("确定要关闭吗？", "提示", MessageBoxButtons.YesNo);

            return (v == System.Windows.Forms.DialogResult.Yes);
        }

        public virtual object ViewResult
        {
            get { return DialogResult; }
            set { DialogResult = (DialogResult)value; }
        }


    }
}